﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DE.Interfaces;
using System.Data;

namespace UserDAL
{
    public class UserAgent:IDEAgent
    {
        public UserAgent()
        {
            m_DALHelper = new UserDALHelper();
        }

        private UserData m_data;
        private UserDALHelper m_DALHelper;

        public IBaseEntityData Data
        {
            get
            {
                return m_data;
            }
            
            set
            {
                m_data = (UserData)value;
            }
        }

        public int Create(IBaseEntityData data)
        {
            this.m_data = (UserData)m_DALHelper.Create(this.m_data);
            return m_data.UserID;
        }

        public int FBCreate(string accesstoken, int requestedDistance)
        {
            this.m_data = (UserData)m_DALHelper.FBCreate(accesstoken, requestedDistance);
            return m_data.UserID;
        }

        public void Update(IBaseEntityData data)
        {
            this.m_data = (UserData)data;
            m_DALHelper.Update(this.m_data);
        }

        public void Delete(int id)
        {
            m_data = null;
            m_DALHelper.Delete(id);
        }

        public void Fetch(int userid,object additions)
        {
            m_data = (UserData)m_DALHelper.Fetch(userid,additions);
        }

        public int Validate(string username, string password, object additions)
        {
            return m_DALHelper.Validate(username,password,additions);
        }

        /// <summary>
        /// Get the friend list of the requested user
        /// </summary>
        /// <returns>Friends table</returns>
        public DataTable GetAllMyFriends(int userid)
        {
            return UserServices.myFriends(userid); 
        }

        public List<string> getLog(int userid, int nlimit)
        {
            return UserServices.getLog(userid, nlimit);
        }

        public void log(int userid, string log)
        {
            UserServices.log(userid, log);
        }
    }
}